
<?php

  $id = !empty($_GET['id'])?$_GET['id']:''; //获取地址栏中参数名是id的值


if(!empty($_POST)){

    //双击编辑功能
    //判断是否是ajax请求
    if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){

       $id = $_POST['id'];
       $val = $_POST['val'];
       $filed = $_POST['filed'];
       $sql = " update `news` set `$filed`='$val' where `id`=$id";
       mysqli_query($link,$sql);
       echo $_rows = mysqli_affected_rows($link);

       die;
    }



  $_rows = edit('news',$id,$_POST);


  // 修改的条件要比其他功能多一个‘=’号
  if($_rows>=0){
     echo"<script>alert('新闻修改成功');location.href='index.php?c=news&a=list&admin=1'</script>";die;
  }else{
     echo"<script>alert('新闻修改失败');history.go(-1)</script>";die;
  }

}

 //查询语句
  $data = getSelectByOne('news',"id=$id");

  $cate_id = $data['cate_id'];

 //查找当前编辑的数据
  $cur_cate = getSelectByOne('cate',"id=$cate_id");

  $cate = editCate($cur_cate);


//加载后台公共视图
 include (View_PATH.$admin.'/communal.html');


?>

